Repository navigation
fix(go2rtc): DELETE streams by src, not name - #40
Merged
Merged
Conversation
The transcoding toggle added in v0.8.2 turned nothing off: with it unchecked, all three channels stayed registered with our ffmpeg:<id>#video=h264#audio=opus#bitrate=2048k source. go2rtc keys DELETE /api/streams off `src`; `name` is what PUT takes. A request that arrives without `src` short-circuits into "list every stream" and answers 200 (internal/streams/api.go), so unregister_stream had always been a no-op that reported success — since PR #32. Nothing depended on removal until the toggle existed, so it never showed. Verified against a live instance with the same stream: DELETE ?name=<id> -> 200, 1310 bytes (the full list), stream stays DELETE ?src=<id> -> 200, 0 bytes, stream removed It did not self-correct because HA's provider only rewrites a stream when it is missing or no producer matches the camera's stream source. The stale entry existed and its producer[0] was exactly that source, so HA skipped the rewrite and kept it alive indefinitely — the same mechanism that makes v0.8.0 work was pinning the wrong state here. - unregister_stream uses src=, plus an empty-name guard so the exact same no-op cannot come back. - New _drop_go2rtc_stream(), used by both the teardown and the transcoding-disabled path. It deletes unconditionally rather than only when _go2rtc_stream_name is set, so leftovers from an earlier run get cleaned up too. - _ensure_go2rtc_stream goes back to only registering: the disabled path just returns False with no HTTP, since it runs on every WebRTC offer and every snapshot. - diagnostics.py now reports entry.options. Not having it is why "was the option actually saved?" could not be answered without asking the user to open the form. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpaDKeLbpQB7EapQBpKoJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The transcoding toggle added in #39 turns nothing off. Verified live: with the checkbox unchecked, all three channels are still registered with our source.
Root cause
internal/streams/api.goin go2rtc:unregister_streamwas sending?name=. With nosrc, the request short-circuits into "list every stream", answers 200 with the full list, andcase "DELETE"never runs. Since we testedresp.status < 300, that counted as success and loggedgo2rtc stream unregistered. It has been this way since #32 — nothing depended on removal until the toggle existed.Proven against the live instance, same stream:
DELETE /api/streams?name=<id>DELETE /api/streams?src=<id>Why it never self-corrected
After the failed teardown, with transcoding off, nothing re-registers — but HA's
_update_stream_sourceonly rewrites when the stream is missing or no producer matches the camera's stream source. The stale stream existed and its producer[0] was exactly that source, so HA skipped the rewrite and kept it alive indefinitely. The very mechanism that makes #37 work was pinning the wrong state here.Why it was hard to spot
The obvious signals — "there's an
ffmpegrunning" and "go2rtc shows 2 online" — hold in both states. HA always registers two sources for any camera, and the second is always anffmpeg:(its own, audio-only:#audio=opus#query=log_level=debug, no#video=). Confirmed on the same instance with an unrelated Tuya camera. What distinguishes the two states is the content of source[1], not the count.Changes
unregister_streamusessrc=, with an empty-name guard so the identical no-op cannot be reintroduced._drop_go2rtc_stream(), used by both the teardown and the transcoding-disabled path. It deletes unconditionally instead of only when_go2rtc_stream_nameis set, so leftovers from an earlier run are cleaned up too._ensure_go2rtc_streamgoes back to only registering: the disabled path returnsFalsewith no HTTP, since it runs on every WebRTC offer and every snapshot.diagnostics.pyreportsentry.options. Not having it is why "was the option actually saved?" could not be answered without asking the user to open the form.Testing
The
?name=vs?src=comparison above was run against the real instance. Post-deploy:xmeye_…_camerastreams disappear from/api/streams. Opening the camera makes HA recreate its own — source[1] becomesffmpeg:<id>#audio=opus#query=log_level=debug, no#video=h264. Chrome goes back to failing, which is what "off" means, and both repair notices clear.#video=h264#audio=opus#bitrate=<slider>kand Chrome plays.optionswithtranscode_h265: false.🤖 Generated with Claude Code
https://claude.ai/code/session_011UpaDKeLbpQB7EapQBpKoJ